package com.pattern.behavioural;

/**
 * @author Ping
 * @date 2022/4/26 15:19
 **/
public class StrategyDemo {
}



class Person {
    /**
     * Constants for travelling
     */
    public static final String BY_CYCLE = "bike" ;
    public static final String BY_TRAIN = "train" ;
    public static final String BY_BUS = "bus" ;
    public static final String BY_PLANE = "airplane" ;

    private String trafficType ;

    public void setTrafficType(String trafficType) {
        this.trafficType = trafficType;
    }

    public double doBudget() {
        double cost = 0.0f ;
        /**
         * Hard coded : bad situation.
         */
        if (trafficType == BY_CYCLE) {
            cost += 10.0f ;
        } else if (trafficType == BY_BUS) {

        } else if (trafficType == BY_TRAIN) {

        }else if (trafficType == BY_PLANE) {

        }

        return cost ;


    }
}
/**
 * OPTIMIZING Part
 */

class PersonTravelling {
    private TravellingStrategy travellingStrategy ;

    public void setTravellingStrategy(TravellingStrategy travellingStrategy) {
        this.travellingStrategy = travellingStrategy;
    }
    public double doBudget() {
        return this.travellingStrategy.getCost() ;
    }

}

interface TravellingStrategy {
    /**
     * abstract method to compute the travelling cost .
     * @return
     */
    public double getCost() ;
}

class CycleStrategy implements TravellingStrategy {
    @Override
    public double getCost() {
        return 10;
    }
}
class BusStrategy implements TravellingStrategy {
    @Override
    public double getCost() {
        return 0;
    }
}

class TrainStrategy implements TravellingStrategy {
    @Override
    public double getCost() {
        return 0;
    }
}
